package com.education.wisdom.controller.app;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.education.common.core.BaseController;
import com.education.common.core.TableDataInfo;
import com.education.common.poi.ExcelUtil;
import com.education.common.pojo.AjaxResult;
import com.education.common.utils.BusinessType;
import com.education.common.utils.LogUtil;
import com.education.wisdom.pojo.Opinion;
import com.education.wisdom.service.IOpinionService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;


/**
 * 意见反馈 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-03-29
 */
@Controller
@Api(tags = {"意见反馈 信息操作处理"})
@CrossOrigin
@Slf4j
@RequestMapping("/appOpinion")
public class AppOpinionController extends BaseController
{
    private String prefix = "system/opinion";
	
	@Autowired
	private IOpinionService opinionService;
	
	@GetMapping()
	public String opinion()
	{
	    return prefix + "/opinion";
	}
	
	@PostMapping("/addSave")
	@ResponseBody
	@ApiOperation("提交意见反馈")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "yjType",value = "类型", dataType = "String"),
			@ApiImplicitParam(name = "yjText",value = "意见内容", dataType = "String"),
			@ApiImplicitParam(name = "yjUserId",value = "创建人", dataType = "String"),
			@ApiImplicitParam(name = "yjIco",value = "图片", dataType = "String"),
			@ApiImplicitParam(name = "yjPhone",value = "联系方式", dataType = "String")
			})
	public void addSave(HttpServletResponse response, HttpServletRequest request, Opinion opinion)throws Exception{
//			Opinion	opinion = new Opinion();
//			opinion.setYjType(yjType);
//			opinion.setYjUserId(yjUserId);
//			opinion.setYjText(yjText);
//			opinion.setYjIco(yjIco);
//			opinion.setYjPhone(yjPhone);	
			log.info(LogUtil.LogInfo("提交意见反馈",new Date()));
			opinion.setCreateTime(new Date());
        	writeJSON(opinionService.insertOpinion(opinion), response, "200", "成功");

	}
	
	@GetMapping("/listByUserId")
	@ResponseBody
	@ApiOperation("意见反馈历史")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNo",value = "当前页", dataType = "Integer"),
			@ApiImplicitParam(name = "pageSize",value = "当前页数据量", dataType = "Integer"),
			@ApiImplicitParam(name = "userId",value = "创建人", dataType = "String")
			})
	public void listByUserId(HttpServletResponse response,HttpServletRequest request,String userId,Integer pageNo,Integer pageSize) throws Exception{
				
			log.info(LogUtil.LogInfo("意见反馈历史",new Date()));
			PageHelper.startPage(pageNo.intValue(),pageSize.intValue());
			List<Opinion> list = opinionService.selectOpinionByUserId(userId);
			writeJSON(new PageInfo<Opinion>(list), response, "200", "成功");

	}
	
	/**
	 * 查询意见反馈列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Opinion opinion)
	{
		startPage();
        List<Opinion> list = opinionService.selectOpinionList(opinion);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出意见反馈列表
	 */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Opinion opinion)
    {
    	List<Opinion> list = opinionService.selectOpinionList(opinion);
        ExcelUtil<Opinion> util = new ExcelUtil<Opinion>(Opinion.class);
        return util.exportExcel(list, "opinion");
    }
	
	/**
	 * 新增意见反馈
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存意见反馈
	 */
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Opinion opinion)
	{		
		return toAjax(opinionService.insertOpinion(opinion));
	}

	/**
	 * 修改意见反馈
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Opinion opinion = opinionService.selectOpinionById(id);
		mmap.put("opinion", opinion);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存意见反馈
	 */
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Opinion opinion)
	{		
		return toAjax(opinionService.updateOpinion(opinion));
	}
	
	/**
	 * 删除意见反馈
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(opinionService.deleteOpinionByIds(ids));
	}
	
}
